package com.taotao.web.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.taotao.common.service.ApiHttpClientService;
import com.taotao.web.bean.TbUser;

@Service
public class UserService {

	@Value("${TAOTAO_SSO_URL}")
	public String  SSO_URL;
	
	@Autowired
	private ApiHttpClientService httpClientService;
	
	private static final ObjectMapper MAPPER = new ObjectMapper();
	
	public TbUser queryUserByToken(String token) {
		String url = SSO_URL + "/service/user/query/"+token;
		try {
			String jsonData = this.httpClientService.doGet(url);
			if(StringUtils.isNotEmpty(jsonData)) {
				TbUser user = MAPPER.readValue(jsonData, TbUser.class);
				return user;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
}
